Vue.component('show-detail', {
    template: `<el-dialog id="user" title="明细查询" :visible.sync="visibleDialog" width="80vw">
    <div style="display:flex;">
        <div style="width:170px;height:170px;border:1px solid #EBEEF5;flex-shrink:0;display: flex;justify-content: center; align-items: center;">
            <el-image style="width:150px;height:150px;" :preview-src-list="[BASE_IMG + data.Picture_URL]" :src="BASE_IMG + data.Picture_URL">
                <div slot="error" class="el-image__error">暂无商品封面</div>
            </el-image>
        </div>
        <el-descriptions style="width:100%" :column="3" border size="small">
            <el-descriptions-item label="商品名称">
                <el-tooltip class="item" effect="dark" :content="data.Article_Name" placement="top-start">
                    <el-input :value="data.Article_Name" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>
            <el-descriptions-item label="商品内码">
                <el-tooltip class="item" effect="dark" :content="data.Article_SerialNumber" placement="top-start">
                    <el-input :value="data.Article_SerialNumber" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>
            <el-descriptions-item label="商品编码">
                <el-tooltip class="item" effect="dark" :content="data.Article_Code" placement="top-start">
                    <el-input :value="data.Article_Code" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>
            <el-descriptions-item label="商品品牌">
                <el-tooltip class="item" effect="dark" :content="data.Brand_Name" placement="top-start">
                    <el-input :value="data.Brand_Name" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>
            <!--<el-descriptions-item label="吊牌价">
                <el-tooltip class="item" effect="dark" :content="data.Unit_Price" placement="top-start">
                    <el-input :value="data.Unit_Price" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>-->
            <el-descriptions-item label="经营商家">
                <el-tooltip class="item" effect="dark" :content="data.Supplier_Name" placement="top-start">
                    <el-input :value="data.Supplier_Name" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>
            <el-descriptions-item label="是否参与团购">
                <el-tooltip class="item" effect="dark" :content="data.Group" placement="top-start">
                    <el-input :value="data.Group" :disabled="true"></el-input>
                </el-tooltip>
            </el-descriptions-item>
            <el-descriptions-item label="京东价">
                <el-tooltip class="item" effect="dark" :content="data.JDCOM_Unit_Price" placement="top-start">
                    <el-input :value="data.JDCOM_Unit_Price" :disabled="true"></el-input>
                </el-tooltip>    
            </el-descriptions-item>
            <el-descriptions-item label="京东链接">
                <el-tooltip class="item" effect="dark" :content="data.JDCOM_URL" placement="top-start">
                    <el-input :value="data.JDCOM_URL" :disabled="true"></el-input>
                </el-tooltip> 
            </el-descriptions-item>
        </el-descriptions>
    </div>
    <div class="table_titel">
        <div class="titel">规格详情</div>
    </div>
    <el-table :data="tableData" stripe border min-height="50vh" style="width: 100%">
        <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
        <el-table-column align="center" prop="Article_Specifications_SerialNumber" width="200" show-overflow-tooltip label="规格流水号"></el-table-column>
        <el-table-column align="center" prop="BarCode" show-overflow-tooltip label="条码"></el-table-column>
        <el-table-column align="center" prop="Specifications_Name" show-overflow-tooltip label="规格名称"></el-table-column>
        <el-table-column prop="Picture_URL" width="140" align="center" label="规格图片">
            <template v-slot="{row}">
                <el-image fit="contain" :preview-src-list="[BASE_IMG + row.Picture_URL]" :src="BASE_IMG + row.Picture_URL" style="width:100px;height: 100px;"></el-image>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="Unit_Price" show-overflow-tooltip label="吊牌价"></el-table-column>
        <el-table-column align="center" prop="JDCOM_URL" show-overflow-tooltip label="京东连接"></el-table-column>
        <el-table-column align="center" prop="JDCOM_Unit_Price" show-overflow-tooltip label="京东价"></el-table-column>
        <el-table-column align="center" prop="Supplier_Name" show-overflow-tooltip label="供应商"></el-table-column>
        <el-table-column align="center" prop="Sales_Unit_Price" show-overflow-tooltip label="销售价格"></el-table-column>
        <el-table-column align="center" prop="Purchase_Unit_Price" show-overflow-tooltip label="一代代发价"></el-table-column>
        <el-table-column align="center" prop="Stock_Remain" show-overflow-tooltip label="今日库存"></el-table-column>
        <el-table-column align="center" prop="Activity_Name" show-overflow-tooltip label="所属活动"></el-table-column>
        <el-table-column align="center" prop="Activity_Unit_Price" show-overflow-tooltip label="活动价格"></el-table-column>
    </el-table>
    <el-pagination style="margin-top: 5px;" background @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :current-page="form.page" :page-sizes="[10, 20, 30, 50]"
        :page-size="form.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
    <div class="table_titel">
        <div class="titel">主图/详情图</div>
    </div>
    <div style="display:flex;">
        <el-carousel v-if="Swiper.length>0" height="400px" style="width:400px;flex-shrink: 0;" indicator-position="none">
            <el-carousel-item v-for="(item,index) in Swiper" :key="index" >
                <el-image style="width:400px;height:400px;" :preview-src-list="[BASE_IMG + item.Picture_URL]" :src="BASE_IMG + item.Picture_URL">
                    <div slot="error" class="el-image__error">加载失败</div>
                </el-image>
            </el-carousel-item>
        </el-carousel>
        <div v-if="Detail.length>0" style="width:100%; height:400px;display:flex;justify-content: center; overflow-y: auto;">
            <div style="width:400px">
                <el-image v-for="(item,index) in Detail" :key="index" style="width:400px;" fit="contain" :preview-src-list="[BASE_IMG + item.Picture_URL]" :src="BASE_IMG + item.Picture_URL">
                    <div slot="error" class="el-image__error">加载失败</div>
                </el-image>
            </div>
        </div>
    </div>
    <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:visible',false)">返回</el-button>
    </span></el-dialog>`,
    props: ['data', 'visible'],
    data() {
        return {
            visibleDialog: false,
            refreshDialog: false,
            Picture_URL: [],
            tableData: [],
            form: {
                SQLSerialNumber: "P_business_article_specifications",
                PaginationNumber: 1,
                RowAmount: 10,
                ExtensionCondition: '',
                Condition: ''
            },
            total: 0,
        }
    },
    computed: {
        Swiper() {//冒泡排序处理轮播图		
            let Picture_URL = this.Picture_URL.filter(i => i.Picture_Type == '0')
            for (var i = 0; i < Picture_URL.length - 1; i++) {
                for (var j = 0; j < Picture_URL.length - i - 1; j++) {
                    if (parseInt(Picture_URL[j].Picture_Order) > parseInt(Picture_URL[j + 1].Picture_Order)) {
                        var count = Picture_URL[j];
                        Picture_URL[j] = Picture_URL[j + 1];
                        Picture_URL[j + 1] = count;
                    };
                };
            };
            return Picture_URL
        },
        Detail() {//冒泡排序处理详情图
            let Picture_URL = this.Picture_URL.filter(i => i.Picture_Type == '1')
            for (var i = 0; i < Picture_URL.length - 1; i++) {
                for (var j = 0; j < Picture_URL.length - i - 1; j++) {
                    if (parseInt(Picture_URL[j].Picture_Order) > parseInt(Picture_URL[j + 1].Picture_Order)) {
                        var count = Picture_URL[j];
                        Picture_URL[j] = Picture_URL[j + 1];
                        Picture_URL[j + 1] = count;
                    };
                };
            };
            return Picture_URL
        },
    },
    watch: {
        visible() {
            this.visibleDialog = this.visible
        },
        visibleDialog(val) {
            this.$emit('update:visible', val)
            if (val) {
                this.form.Condition = window.btoa(unescape(encodeURIComponent(this.data.Article_SerialNumber)));
                this.getList(this.form);
                this.getData()
            }
        },
    },
    methods: {
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        expandChange(row) {
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data: {
                    SQLSerialNumber: "A_business_supplier_article1",
                    Condition: window.btoa(unescape(encodeURIComponent(row.Article_Specifications_SerialNumber))),
                    ExtensionCondition: '',
                },
                success: function (Result) {
                    row.Children = Result
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList(data) {
            const that = this
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    // Result.Rows.forEach(item=>{
                    //     item['Children'] = []
                    // })
                    that.tableData = Result.Rows;
                    console.log(Result.Rows);
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    that.refreshDialog = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getData() {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                type: 'POST',
                data: {
                    Data: 'business_article_pic',
                    Condition: "Article_SerialNumber = '" + this.data.Article_SerialNumber + "'",
                },
                success: function (Result) {
                    that.Picture_URL = Result;
                },
                complete: function (XMLHttpRequest) {
                    that.refreshDialog = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        }
    }
})
new Vue({
    el: '#app',
    data() {
        return {
            form: {
                // P_business_article_info4
                SQLSerialNumber: "P_business_article_info4",
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
                Condition: '',
                ExtensionCondition: '',
                Article_Name: '',
                Brand_SerialNumber: '',
                Shelf: '',
                Supplier_Name: '',
                gross_margin1: '',
                gross_margin2: '',
                discount1: '',
                discount2: '',
                Purchase_Unit_Price1: '',
                Purchase_Unit_Price2: '',
                Sales_Unit_Price1: '',
                Sales_Unit_Price2: '',
                Article_SerialNumber: ''
            },
            total: 0,
            count: 0,
            tableData: [],
            ExportData: [],
            brand: [], //商品品牌
            classify: [],
            business_article_classify: [],
            loading: false,
            dialogVisible: false,
            Article_SerialNumber: '',
            multipleSelection: [],
            downloadImagesLoading: false,//是否下载图片中
            defaultProps: {
                children: 'Children',
                label: 'Classify_Name',
                value: 'Classify_SerialNumber',
                multiple: true
            },
        }
    },
    mounted() {
        this.getData();
        this.getList(this.form);//前端分页
    },
    methods: {
        getData() {
            const that = this;
            const Condition = "Row_Status='0'";
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                type: 'POST',
                data: {
                    Data: 'business_brand',
                    Condition,
                },
                success: function (res) {
                    that.brand = res;
                },
                error: function () {
                    that.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                type: 'POST',
                data: {
                    SQLSerialNumber: 'P_examine_article',
                    PaginationNumber: 1,//页数
                    RowAmount: 10,//每页数据条数
                    Condition: '',
                    ExtensionCondition: '',
                },
                success: function (res) {
                    that.count = parseInt(res.TotalRows)
                },
                error: function () {
                    that.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            })
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/getAllClassify`,
                type: 'GET',
                success: function (data) {
                    that.classify = data
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        examine() {//审核
            window.location.href = './examine.html'
        },
        log() {
            window.location.href = './log.html'
        },
        Add() {
            window.location.href = './add.html'
        },
        handleJD(url) {
            window.parent.document.location.href = url
        },
        Show(Article_SerialNumber) {
            this.Article_SerialNumber = Article_SerialNumber
            this.dialogVisible = true
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        handleBatchAdd(command) {
            const that = this;
            if (this.multipleSelection.filter(i => i.Shelf == command).length > 0) {
                this.$confirm(command == '0' ? '是否将勾选的商品下架?' : '是否将勾选的商品上架', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'info'
                }).then(() => {
                    if (command == '1') {//生效
                        //1.遍历已选查询对应数据
                        let Shelf_Date = getYMDHMSDate();
                        let Condition = "";
                        this.multipleSelection.filter(i => i.Shelf == command).forEach(item => {
                            if (Condition) {
                                Condition = Condition + " OR Article_SerialNumber='" + item.Article_SerialNumber + "'"
                            } else {
                                Condition = "Article_SerialNumber='" + item.Article_SerialNumber + "'"
                            }
                        });
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                            type: 'POST',
                            data: {
                                Data: 'business_article_info',
                                Condition
                            },
                            success: function (business_article_info) {
                                let base_operation_log = [];
                                business_article_info.forEach(item => {
                                    item.Shelf = (command == '0' ? '1' : '0');
                                    item.Shelf_Date = Shelf_Date;
                                    base_operation_log.push(generateLog('商品:' + that.multipleSelection.filter(i => i.Article_SerialNumber == item.Article_SerialNumber)[0].Article_Name + (command == '0' ? '下' : '上') + '架', '平台端操作', 'business_article_info', JSON.stringify({ Modify: { business_article_info: item } })))
                                })
                                $.ajax({
                                    headers: requestHeaders(),
                                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                                    type: 'POST',
                                    data: {
                                        Data: JSON.stringify({
                                            Modify: { business_article_info },
                                            Add: { base_operation_log }
                                        })
                                    },
                                    success: function (res) {
                                        if (res.Status === 'success') {
                                            that.$refs.multipleTable.clearSelection()
                                            that.$message({
                                                type: 'success',
                                                message: '操作成功!'
                                            });
                                            that.getList(that.form);
                                        } else {
                                            that.$message.error("删除失败，请稍后再试")
                                        }
                                    },
                                    error: function () {
                                        that.$message.error("删除失败，请稍后再试")
                                    },
                                    complete: function (XMLHttpRequest) {
                                        that.loading = false
                                        requestPretreatment(XMLHttpRequest);
                                    },
                                    dataType: "json"
                                })
                            },
                            error: function () {
                                that.$message.error("删除失败，请稍后再试")
                            },
                            complete: function (XMLHttpRequest) {
                                that.loading = false
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    } else if (command == '0') {//失效
                        //1.遍历已选查询对应数据
                        let Shelf_Date = getYMDHMSDate();
                        let Condition = "", ExtensionCondition = "";
                        this.multipleSelection.filter(i => i.Shelf == command).forEach(item => {
                            if (Condition) {
                                Condition = Condition + " OR Article_SerialNumber='" + item.Article_SerialNumber + "'";
                                ExtensionCondition = ExtensionCondition + " OR business_supplier_article.Article_SerialNumber='" + item.Article_SerialNumber + "'";
                            } else {
                                Condition = "Article_SerialNumber='" + item.Article_SerialNumber + "'"
                                ExtensionCondition = "business_supplier_article.Article_SerialNumber='" + item.Article_SerialNumber + "'"
                            }
                        });
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                            type: 'POST',
                            data: {
                                Data: 'business_article_info',
                                Condition
                            },
                            success: function (business_article_info) {
                                $.ajax({
                                    headers: requestHeaders(),
                                    url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumberWithOriginal`,
                                    type: 'POST',
                                    data: {
                                        SQLSerialNumber: 'A_business_activity_article3',
                                        Condition: '',
                                        ExtensionCondition: window.btoa(unescape(encodeURIComponent(ExtensionCondition)))
                                    },
                                    success: function (business_activity_article) {
                                        let base_operation_log = [];
                                        business_article_info.forEach(item => {
                                            item.Shelf = (command == '0' ? '1' : '0');
                                            item.Shelf_Date = Shelf_Date;
                                            base_operation_log.push(generateLog('商品:' + that.multipleSelection.filter(i => i.Article_SerialNumber == item.Article_SerialNumber)[0].Article_Name + (command == '0' ? '下' : '上') + '架', '平台端操作', 'business_article_info', JSON.stringify({ Modify: { business_article_info: item } })))
                                        })
                                        business_activity_article.forEach(item => {
                                            item.Row_Status = '1';
                                        })
                                        $.ajax({
                                            headers: requestHeaders(),
                                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                                            type: 'POST',
                                            data: {
                                                Data: JSON.stringify({
                                                    Modify: { business_article_info, business_activity_article },
                                                    Add: { base_operation_log }
                                                })
                                            },
                                            success: function (res) {
                                                if (res.Status === 'success') {
                                                    that.$refs.multipleTable.clearSelection()
                                                    that.$message({
                                                        type: 'success',
                                                        message: '操作成功!'
                                                    });
                                                    that.getList(that.form);
                                                } else {
                                                    that.$message.error("删除失败，请稍后再试")
                                                }
                                            },
                                            error: function () {
                                                that.$message.error("删除失败，请稍后再试")
                                            },
                                            complete: function (XMLHttpRequest) {
                                                that.loading = false
                                                requestPretreatment(XMLHttpRequest);
                                            },
                                            dataType: "json"
                                        })
                                    },
                                    error: function () {
                                        that.$message.error("删除失败，请稍后再试")
                                    },
                                    complete: function (XMLHttpRequest) {
                                        requestPretreatment(XMLHttpRequest);
                                    },
                                    dataType: "json"
                                })
                            },
                            complete: function (XMLHttpRequest) {
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    }
                }).catch(() => { });
            } else {
                this.$message({
                    type: 'warning',
                    message: '至少要选择1个商品!(可能选中商品以全部' + (command == '1' ? '生效' : '失效') + ')'
                });
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        downloadTemplate(command) {
            if (command == "Article") {
                window.location.href = './download/导入商品模板表.新.xlsx';
            } else if (command == "BarCode") {
                window.location.href = './download/导入条形码模板.xlsx';
            } else if (command == "UpData") {
                window.location.href = './download/更新商品模板.xlsx';
            }
        },
        importTemplate(command) {
            if (command == "Article") {
                window.location.href = './import1.html';
            } else if (command == "BarCode") {
                window.location.href = './import_barcode.html';
            } else if (command == "UpData") {
                window.location.href = './import_edit.html';
            }
        },
        handleImages() {
            const that = this;
            if (this.multipleSelection.length > 0) {
                let arr = [];
                this.multipleSelection.forEach(item => {
                    if (!arr.some(i => i.Article_SerialNumber == item.Article_SerialNumber)) {
                        arr.push(item.Article_SerialNumber);
                    }
                })
                console.log(arr);
                this.downloadImagesLoading = true;
                that.$message.success("当前正在下载图片，请勿刷新页面!");
                $.ajax({
                    headers: requestHeaders1(),
                    type: 'POST',
                    url: `${BASE_URL1}/downloadArticleImages`,
                    xhrFields: {
                        responseType: 'blob',
                    },
                    data: {
                        Data: JSON.stringify(arr)
                    },
                    success: function (blob, statusText, jqXHR) {
                        const link = document.createElement('a');
                        link.href = window.URL.createObjectURL(blob);
                        const contentDisposition = jqXHR.getResponseHeader('Content-Disposition');
                        console.log(contentDisposition);
                        if (contentDisposition && contentDisposition.indexOf('attachment') !== -1) {
                            var filenameMatch = contentDisposition.match(/filename=([^]*)/);
                            if (filenameMatch && filenameMatch.length > 1) {
                                link.download = filenameMatch[1]; // 设置下载文件的名称
                            }
                        }
                        document.body.appendChild(link); // 将链接添加到 DOM 中
                        link.click(); // 模拟点击下载
                        document.body.removeChild(link); // 下载完成后移除链接
                        window.URL.revokeObjectURL(link.href);
                        that.$message.success("下载完成!");
                    },
                    complete: function (XMLHttpRequest) {
                        that.downloadImagesLoading = false;
                    },
                });
            } else {
                that.$message({
                    type: 'warning',
                    message: '请选择商品后再进行下载'
                })
            }

        },
        moreConfig(command, row) {
            if (command == 'Edit') {
                this.Edit(row.Article_SerialNumber);
            } else if (command == 'Remove') {
                this.Remove(row);
            } else if (command == 'Download0') {
                this.Download0(row.Article_SerialNumber);
            } else if (command == 'Download1') {
                this.Download1(row.Article_SerialNumber);
            } else if (command == 'Shelf') {
                const that = this;
                let obj = deepClone(row);
                console.log(obj);
                this.$confirm(`是否要${obj.Shelf == '0' ? '下' : '上'}架该商品继续?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }).then(() => {
                    obj.Shelf_Date = getYMDHMSDate();
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                        type: 'POST',
                        data: {
                            Data: 'business_article_info',
                            Condition: "Article_SerialNumber='" + row.Article_SerialNumber + "'"
                        },
                        success: function (data) {
                            if (obj.Shelf == '0') {
                                data[0].Shelf = '1'
                            } else {
                                data[0].Shelf = '0'
                            }
                            $.ajax({
                                headers: requestHeaders(),
                                url: `${BASE_URL2}/generalBusiness/generalSave`,
                                type: 'POST',
                                data: {
                                    Data: JSON.stringify({
                                        Modify: { business_article_info: data },
                                        Add: { base_operation_log: [generateLog('商品:' + obj.Article_Name + (obj.Shelf == '0' ? '下' : '上') + '架', '平台端操作', 'business_article_info', JSON.stringify({ Modify: { business_article_info: data } }))] }
                                    })
                                },
                                success: function (res) {
                                    if (res.Status === 'success') {
                                        that.$message({
                                            type: 'success',
                                            message: '操作成功!'
                                        });
                                        that.getList(that.form);
                                    } else {
                                        that.$message.error("删除失败，请稍后再试")
                                    }
                                },
                                error: function () {
                                    that.$message.error("删除失败，请稍后再试")
                                },
                                complete: function (XMLHttpRequest) {
                                    that.loading = false
                                    requestPretreatment(XMLHttpRequest);
                                },
                                dataType: "json"
                            })
                        },
                        error: function () {
                            that.$message.error("删除失败，请稍后再试")
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })

                }).catch(() => { });
            }
        },
        Download0(Article_SerialNumber) {//下载主图
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                data: {
                    Data: 'business_article_pic',
                    Condition: "Article_SerialNumber='" + Article_SerialNumber + "' and Row_Status='0' and Picture_Type='0'",
                },
                success: function (Result) {
                    let Files = "";
                    Result.forEach(item => {
                        if (Files) {
                            Files = Files + "," + item.Picture_URL;
                        } else {
                            Files = item.Picture_URL;
                        }
                    })
                    if (Files) {
                        const url = `${BASE_URL2}/login/downloadZipFile?Files=${Files}`;
                        const a = document.createElement('a');
                        a.style.display = 'none';
                        a.href = url;
                        document.body.appendChild(a);
                        a.click(); // 触发点击
                        a.remove();
                    }else{
                        that.$message({
                            type: 'warning',
                            message: '暂无可导出的图片!'
                        });
                    }
                    
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Download1(Article_SerialNumber) {//下载详情图
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                data: {
                    Data: 'business_article_pic',
                    Condition: "Article_SerialNumber='" + Article_SerialNumber + "' and Row_Status='0' and Picture_Type='1'",
                },
                success: function (Result) {
                    let Files = "";
                    Result.forEach(item => {
                        if (Files) {
                            Files = Files + "," + item.Picture_URL;
                        } else {
                            Files = item.Picture_URL;
                        }
                    })
                    if (Files) {
                        const url = `${BASE_URL2}/login/downloadZipFile?Files=${Files}`;
                        const a = document.createElement('a');
                        a.style.display = 'none';
                        a.href = url;
                        document.body.appendChild(a);
                        a.click(); // 触发点击
                        a.remove();
                    }else{
                        that.$message({
                            type: 'warning',
                            message: '暂无可导出的图片!'
                        });
                    }

                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        downloadAddTemplate() {//新增商品模板
            window.location.href = './download/导入商品模板表.xlsx';
        },
        downloadEditTemplate() {//更新商品模板
            window.location.href = './download/更新商品信息导入模板表.xlsx';
        },
        getList(form) {//换页方法
            const that = this;
            let data = deepClone(form);
            let SQL = "";
            if (data.Article_Name) {
                SQL = SQL + " and business_article_info.Article_Name LIKE '%" + data.Article_Name + "%' "
            }
            if (data.Article_SerialNumber) {
                SQL = SQL + " and business_article_info.Article_SerialNumber LIKE '%" + data.Article_SerialNumber + "%' "
            }
            // 根据商品名称筛选
            if (data.Supplier_Name) {
                SQL = SQL + " and business_supplier_info.Supplier_Name LIKE '%" + data.Supplier_Name + "%' "
            }
            // 根据品牌筛选
            if (data.Brand_SerialNumber) {
                SQL = SQL + " and business_article_info.Brand_SerialNumber LIKE '%" + data.Brand_SerialNumber + "%' "
            }
            // 根据是否参与团购
            if (data.Shelf) {
                SQL = SQL + " and business_article_info.Shelf = '" + data.Shelf + "' "
            }
            if (this.business_article_classify.length > 0) {
                let str = "";
                this.business_article_classify.forEach(item => {
                    if (str) {
                        str = str + " or business_article_classify.Classify_SerialNumber = '" + item[item.length - 1] + "' \r\n"
                    } else {
                        str = "business_article_classify.Classify_SerialNumber = '" + item[item.length - 1] + "' \r\n"
                    }

                })
                SQL = SQL + " and (" + str + ") \r\n";
            }
            //毛利率
            if (data.gross_margin1) {
                SQL = SQL + " and CAST(IFNULL(ROUND((1 - business_daily_purchase_unitprice.Purchase_Unit_Price/business_daily_execute_unitprice.Sales_Unit_Price)*100),'0') As FLOAT) >= '" + data.gross_margin1 + "'";
            }
            if (data.gross_margin2) {
                SQL = SQL + " and CAST(IFNULL(ROUND((1 - business_daily_purchase_unitprice.Purchase_Unit_Price/business_daily_execute_unitprice.Sales_Unit_Price)*100),'0') As FLOAT) <= '" + data.gross_margin2 + "'";
            }
            //区间
            if (data.discount1) {
                SQL = SQL + " and CAST(IFNULL(ROUND(business_daily_execute_unitprice.Sales_Unit_Price/business_article_specifications.JDCOM_Unit_Price*100),'0') As FLOAT) >= '" + data.discount1 + "'";
            }
            if (data.discount2) {
                SQL = SQL + " and CAST(IFNULL(ROUND(business_daily_execute_unitprice.Sales_Unit_Price/business_article_specifications.JDCOM_Unit_Price*100),'0') As FLOAT) <= '" + data.discount2 + "'";
            }
            //区间
            if (data.Purchase_Unit_Price1 > 0) {
                SQL = SQL + " and CAST(IFNULL(business_daily_purchase_unitprice.Purchase_Unit_Price,'0') As FLOAT) >= '" + data.Purchase_Unit_Price1 + "' "
            }
            if (data.Purchase_Unit_Price2 > 0) {
                SQL = SQL + " and CAST(IFNULL(business_daily_purchase_unitprice.Purchase_Unit_Price,'0') As FLOAT) <= '" + data.Purchase_Unit_Price2 + "' "
            }
            if (data.Sales_Unit_Price1 > 0) {
                SQL = SQL + " and CAST(IFNULL(business_daily_execute_unitprice.Sales_Unit_Price,'0') As FLOAT) >= '" + data.Sales_Unit_Price1 + "' "
            }
            if (data.Sales_Unit_Price2 > 0) {
                SQL = SQL + " and CAST(IFNULL(business_daily_execute_unitprice.Sales_Unit_Price,'0') As FLOAT) <= '" + data.Sales_Unit_Price2 + "' "
            }
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(SQL)));
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    Result.Rows.forEach(item => {
                        item.is1 = false;
                        item.is2 = false;
                    })
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        handleStaplesCode1(row) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                data: {
                    Data: "business_article_specifications",
                    Condition: "Article_Specifications_SerialNumber='" + row.Article_Specifications_SerialNumber + "'"
                },
                success: function (data) {
                    if (data.length == 1) {
                        data[0].Staples_Code = row.Staples_Code1;
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                            type: 'POST',
                            data: {
                                Data: JSON.stringify({
                                    Modify: { business_article_specifications: data },
                                    Add: { base_operation_log: [generateLog('修改商品A公司编码', '平台端操作', 'business_article_info', JSON.stringify({ Modify: { business_article_specifications: [row] } }))] }
                                })
                            },
                            success: function (res) {
                                if (res.Status === 'success') {
                                    that.$message({
                                        type: 'success',
                                        message: '操作成功!'
                                    });
                                    row.is1 = false;
                                } else {
                                    that.$message.error("操作失败，请稍后再试")
                                }
                            },
                            error: function () {
                                that.$message.error("操作失败，请稍后再试")
                            },
                            complete: function (XMLHttpRequest) {
                                that.loading = false
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        handleStaplesCode2(row) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                data: {
                    Data: "business_article_specifications",
                    Condition: "Article_Specifications_SerialNumber='" + row.Article_Specifications_SerialNumber + "'"
                },
                success: function (data) {
                    if (data.length == 1) {
                        data[0].Staples_Code1 = row.Staples_Code2;
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                            type: 'POST',
                            data: {
                                Data: JSON.stringify({
                                    Modify: { business_article_specifications: data },
                                    Add: { base_operation_log: [generateLog('修改商品B公司编码', '平台端操作', 'business_article_info', JSON.stringify({ Modify: { business_article_specifications: [row] } }))] }
                                })
                            },
                            success: function (res) {
                                if (res.Status === 'success') {
                                    that.$message({
                                        type: 'success',
                                        message: '操作成功!'
                                    });
                                    row.is2 = false;
                                } else {
                                    that.$message.error("操作失败，请稍后再试")
                                }
                            },
                            error: function () {
                                that.$message.error("操作失败，请稍后再试")
                            },
                            complete: function (XMLHttpRequest) {
                                that.loading = false
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        })
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Edit(Article_SerialNumber) {
            sessionStorage.setItem("Article_SerialNumber", Article_SerialNumber)
            window.location.href = './edit.html?Article_SerialNumber=' + Article_SerialNumber
        },
        Remove(row) {//删除内容
            const that = this
            this.$confirm('警告！此操作将删除该商品, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                row.Row_Status = '1';
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({
                            Modify: { business_article_info: [row] },
                            Add: { base_operation_log: [generateLog('删除商品信息', '平台端操作', 'business_article_info', JSON.stringify({ Modify: { business_article_info: [row] } }))] }
                        })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            that.getList(that.form);
                        } else {
                            that.$message.error("删除失败，请稍后再试")
                        }
                    },
                    error: function () {
                        that.$message.error("删除失败，请稍后再试")
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        },
        Export(form) {
            const that = this;
            this.loading = true;
            let data = deepClone(form);
            data.SQLSerialNumber = 'P_business_supplier_article1';
            data.Condition = "";
            data.ExtensionCondition = "";
            // data.Condition = window.btoa(unescape(encodeURIComponent("%" + data.Article_Name + "%")))
            // let SQL = "";
            // if (data.Brand_SerialNumber) {
            //     SQL = SQL + " and business_article_info.Brand_SerialNumber = '" + data.Brand_SerialNumber + "' "
            // }
            // data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(SQL)));
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    if (Result.length > 0) {
                        const wb = XLSX.utils.book_new();
                        const ws_data = [
                            ["商品内码", "商品名称", "品牌", "一级分类", "二级分类", "三级分类", "A公司编码", "B公司编码", "封面图", "品牌内码", "规格内码", "规格", "规格封面", "规格京东价格", "规格京东链接", "供应商", "供应商编号", "平台价", "一代代发价", "折扣价", "毛利率", "每日库存", "上架状态", "可适用积分", "抵扣类型", "抵扣比例", "是否参与团购", "活动价格"],
                        ];
                        Result.forEach(item => {
                            ws_data.push([
                                item.Article_SerialNumber,
                                item.Article_Name,
                                item.Brand_Name,
                                item.Classify_Name.split('-')[0],
                                item.Classify_Name.split('-')[1],
                                item.Classify_Name.split('-')[2],
                                item.Staples_Code,
                                item.Staples_Code1,
                                BASE_IMG + item.Picture_URL,
                                item.Brand_SerialNumber,
                                item.Article_Specifications_SerialNumber,
                                item.Specifications_Name,
                                BASE_IMG + item.Picture_URL1,
                                item.JDCOM_Unit_Price,
                                item.JDCOM_URL,
                                item.Supplier_Name,
                                item.Supplier_SerialNumber,
                                item.Sales_Unit_Price,
                                item.Purchase_Unit_Price,
                                item.JDCOM_Unit_Price1 > 0 && item.Sales_Unit_Price > 0 ? (accDiv(item.Sales_Unit_Price, item.JDCOM_Unit_Price1) * 100).toFixed(2) + '%' : '-',
                                item.Purchase_Unit_Price > 0 && item.Sales_Unit_Price > 0 ? (accSub(1, accDiv(item.Purchase_Unit_Price, item.Sales_Unit_Price)) * 100).toFixed(2) + '%' : '-',
                                item.Total_stock,
                                item.Shelf == '0' ? '上架' : '下架',
                                item.Cash_Point == '0' ? '现金积分' : '',
                                item.Deduction_Type == '0' ? '固定抵扣' : '百分比',
                                item.Deduction_Limit,
                                item.Group,
                                item.Activity_Unit_Price,
                            ])
                        })
                        const ws = XLSX.utils.aoa_to_sheet(ws_data);
                        ws['!cols'] = [];
                        ws_data[0].forEach(item => {
                            ws['!cols'].push({ alignment: { horizontal: "center" }, wpx: 150 });
                        })
                        XLSX.utils.book_append_sheet(wb, ws, "商品信息");
                        XLSX.writeFile(wb, '商品信息' + (+new Date()) + ".xlsx");
                        that.$message({
                            message: '已导出商品信息！',
                            type: 'success'
                        })
                    } else {
                        that.$message({
                            message: '暂无可导出的数据',
                            type: 'warning'
                        })
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false;
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
    },
})